/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package desktopapplication1;

import java.util.List;
import app.Com;
import app.Parameters;
import core.SerialPort;

public class App {

    public static void main(String[] args) throws Exception {
        // looks for free serial ports
        SerialPort free = new SerialPort();
        List<String> portList = free.getFreeSerialPort();
        for (String string : portList) {
            System.out.println(string);
        }
        // Settings parameters COM1.

        Parameters settings = new Parameters();
        settings.setPort("COM6");
        settings.setBaudRate("19200");



        //Instance COM1.
        Com com5 = new Com(settings);

        // Settings parameters COM·.
//        settings.setPort("COM3");
//        settings.setBaudRate("9600");
//        //Instance COM3.
//        Com com3 = new Com(settings);
        //Write COM1.

        char caracterInicio = (char) 2;
        char caracterFIN = (char) 13;

//        com5.sendString(caracterInicio + "0J4" + caracterFIN,0);

//        for (int i = 0; i < 4; i++) {
//             char c = (char)13;
//            System.out.println(">>Send G");
//            com5.sendString("gustavo "+c, i);
//
//        }
        //Read COM3
//        for (int i = 0; i < 4; i++) {
//            System.out.println("<<Receive "+com5.receiveSingleString());
//        }



//        while (true) {
//            System.out.println("<<Receive " + com5.receiveSingleString());
//        }
        String recibido = "";
        char a = caracterInicio;//llenar con cualquier cosa


        boolean bandera = false;
//        while (true) {
            

            while (!(a == '\r')) {
                a = com5.receiveSingleChar();
                recibido += a;
            }
            System.out.println(recibido.trim());



//        }




    }
}
